package com.lexian.controller;


import com.lexian.entity.Cartitem;
import com.lexian.entity.vo.GoodsVo;
import com.lexian.service.CartitemService;
import com.lexian.service.GoodsService;
import com.lexian.utils.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private CartitemService cartitemService;
    //获取所有商品信息
    @GetMapping("getAllInfo")
    public CommonResponse getAllInfo(){
        List<GoodsVo> list = goodsService.getInfo();
        return CommonResponse.ok().data("list",list);
}

    /**
     * 获取购物车商品
     * @param cusId
     * @return
     */
    @GetMapping("getCartGoods/{cusId}")
    public CommonResponse getCartGoods(@PathVariable long cusId){
        return CommonResponse.ok().data("list_CartGoods",goodsService.getCartGoods(cusId));
    }

<<<<<<< HEAD
    //获取门店商品
    @GetMapping("getByInfo/{gid}")
    public CommonResponse getByInfo(long gid){
        return CommonResponse.ok().data("list_ByInfo",goodsService.getByInfo(gid));
    }
=======
    /**
     * 删除用户的购物车的商品
     * @param cartItemId
     * @return
     */
    @GetMapping("deleteCartGoods/{cartItemId}")
    public CommonResponse deleteCartGoods(@PathVariable long cartItemId){
        cartitemService.removeById(cartItemId);
        return CommonResponse.ok();
    }


    /**
     * 商品加入购物车
     * @param goodsId
     * @param cartId
     * @param num
     */
    @GetMapping("insertCartGoods/{goodsId}/{cartId}/{num}")
    public CommonResponse insertCartGoods(@PathVariable long goodsId,@PathVariable long cartId,@PathVariable Double num){
        Cartitem cartitem=new Cartitem();
        cartitem.setGoodsId(goodsId);
        cartitem.setNum(num);
        cartitem.setCartId(cartId);
        cartitemService.save(cartitem);
        return CommonResponse.ok();
    }


>>>>>>> a1e4429361f088c5d2c38576e7d531c8ac58ca25
}

